#!/bin/sh

# Slackware build script for Azureus/Vuze
# Written by Chris Lawrence <selivanow@gmail.com>

PRGNAM=vuze
VERSION=${VERSION:-4.3.0.4}
ARCH=${ARCH:-i486}
BUILD=${BUILD:-2}
TAG=${TAG:-_SBo}

if [ "$ARCH" = "x86_64" ]; then
  LIBDIRSUFFIX="64"
  ARCHIVE=Vuze_${VERSION}_linux-$ARCH.tar.bz2
else
  ARCH=i486
  LIBDIRSUFFIX=""
  ARCHIVE=Vuze_${VERSION}_linux.tar.bz2
fi

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

rm -rf $PKG
mkdir -p $TMP $PKG/usr/lib${LIBDIRSUFFIX} $PKG/usr/bin $OUTPUT
tar xvf $CWD/$ARCHIVE -C $PKG/usr/lib${LIBDIRSUFFIX}

# Set PROGRAM_DIR and MOZILLA_FIVE_HOME in the azureus program script
sed "s%@LIBDIR@%/usr/lib${LIBDIRSUFFIX}%g" $CWD/vuze-set_paths.diff | \
    patch -p1 -d $PKG/usr/lib${LIBDIRSUFFIX}/vuze

# Create two new symlinks in /usr/bin
( cd $PKG/usr/bin
  ln -s ../lib${LIBDIRSUFFIX}/$PRGNAM/azureus
  ln -s ../lib${LIBDIRSUFFIX}/$PRGNAM/vuze
)

mkdir -p $PKG/usr/share/{applications,pixmaps}
cat $CWD/vuze.desktop > $PKG/usr/share/applications/vuze.desktop
( cd $PKG/usr/share/pixmaps ; ln -s ../../lib${LIBDIRSUFFIX}/vuze/vuze.png )

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
